// request.js专门处理请求
// cart.js 放购物车请求
//goods.js 商品的请求
import http from './http.js';

import api from './api.js';
// 请求商品
export  function getGoods(num, classid = '') {
    return http({
        method:'GET',
        url:api.getGoods,
        params:{
            project_id:18,
            limit: num,
            classify_id: classid
        }
    })
}

// 注册请求
export function registration(data) {
    return http({
        method:'POST',
        url:api.registration,
        data: data
    })
}

// 登录请求
export function loginRequest(data) {
    return http({
        method: 'POST',
        url:api.loginRequest,
        data: data
    })
}

// 退出登录请求
export function logout() {
    return http({
        method: 'POST',
        url:api.logout
    })
}

// 请求单个商品
export function goodsId(data) {
    return http({
        method: 'GET',
        url:api.goodsId + data,
    })
}

// 获取购物车商品
export function getCart() {
    return http({
        method: 'GET',
        url:api.getCart,
        params:{
            project_id:18
        },
    })
}

// 添加购物车商品
export function addCart(data) {
    return http({
        method: 'POST',
        url:api.addCart,
        data: {
            goods_id: data.id,
            num: data.num,
            project_id: 18
        },
    })
}

// 更新购物车商品的数量
export function upCart(data) {
    return http({
        method: 'PUT',
        url:api.upCart + data.id,
        data: {
            num: data.num,
        },
    })
}

// 删除购物车商品
export function delCart(id) {
    return http({
        method: 'DELETE',
        url:api.delCart + id,
    })
}

// 请求城市地址
export function getcity() {
    return http({
        method: 'GET',
        url:api.getcity
    })
}

// 添加收货地址
export function addcity(data) {
    return http({
        method: 'POST',
        url:api.addcity,
        data: {
            name: data.name,
            phone: data.phone,
            area: data.area,
            area_name: data.area_name,
            desc: data.desc
        },
    })
}

// 删除收货地址
export function delcity(id) {
    return http({
        method: 'DELETE',
        url:api.delcity + id,
    })
}

// 请求城市地址
export function getmyaddress() {
    return http({
        method: 'GET',
        url:api.getmyaddress
    })
}

// 更改收货地址
export function upaddress(data) {
    return http({
        method: 'PUT',
        url:api.upaddress + data.id,
        data: {
            name: data.name,
            phone: data.phone,
            area: data.area,
            desc: data.desc,
            area_name: data.area_name,
        },
    })
}

// 添加订单
export function addorder(data) {
    return http({
        method: 'POST',
        url:api.addorder,
        data: {
            goods_info: data.goods_info,
            addr_id: data.addr_id,
            project_id: 18
        },
    })
}

// 获取订单列表
export function getorder(data) {
    return http({
        method: 'GET',
        url:api.getorder,
        params: data
    })
}

// 更新订单信息 
export function uporder(data) {
    return http({
        method: 'PUT',
        url:api.uporder + data.id,
        data: data
    })
}

// 删除订单信息 
export function delorder(id) {
    return http({
        method: 'DELETE',
        url:api.delorder + id
    })
}
